/**
 * Created by lcy on 2015/7/2.
 */
//css: link(rel="stylesheet", href="plugins/ngAlert/ngAlert.css")
angular.module('ngAlert',['ngDialog'])
    .factory("ngAlert",function(ngDialog){
        var Alert = function(content,callback) {
            ngDialog.open({
                template:
                    '<p>' + content + '</p>' +
                    '<div class="ngdialog-buttons">' +
                    '<button type="button" class="ngdialog-button ngdialog-button-primary" ng-click="closeThisDialog()">确定</button>' +
                    '</div>',
                preCloseCallback: function(value) {
                    if(typeof callback == "function") {
                        callback();
                    }
                    return true;
                },
                plain: true
            });
        };
        var Confirm = function(content,callback) {
            ngDialog.openConfirm({
                template: '<div class="ngdialog-message">' + content + '</div>\
                <div class="ngdialog-buttons">\
                    <button type="button" class="ngdialog-button ngdialog-button-secondary" ng-click="closeThisDialog()">否</button>\
                    <button type="button" class="ngdialog-button ngdialog-button-primary" ng-click="confirm()">是</button>\
                </div>',
                className: 'ngdialog-theme-default',
                plain: true
            }).then(function () {
                if(typeof callback == "function") {
                    callback();
                }
            });
        };
        var Prompt = function(content,callback) {
            ngDialog.openConfirm({
                template: '<div class="ngdialog-message">' + content + '</div>\
                <div class="ngdialog-message"><input class="ngAlertInput" ng-model="confirmValue" /></div>\
                <div class="ngdialog-buttons">\
                    <button type="button" class="ngdialog-button ngdialog-button-secondary" ng-click="closeThisDialog()">否</button>\
                    <button type="button" class="ngdialog-button ngdialog-button-primary" ng-click="confirm(confirmValue)">是</button>\
                </div>',
                className: 'ngdialog-theme-default',
                plain: true
            }).then(function (value) {
                if(typeof callback == "function") {
                    callback(value);
                }
            });
        };
        var autoHide = function(content,delay) {
        	    var time = 1000 || delay;
                var dialog = ngDialog.open({
                    template: '<p>' + content + '</p>',
                    plain: true,
                    closeByDocument: false,
                    closeByEscape: false,
                    overlay:false
                });
                setTimeout(function () {
                    dialog.close();
                }, time);
        };
        return {
            Alert:Alert,
            Confirm:Confirm,
            Prompt:Prompt,
            autoHide:autoHide
        }
    });